Instructions: Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly. We would love to see you show off your creativity!
I will create a scatterplot using the mtcars data set of Miles/gallon (mpg) vs Gross horsepower (hp) using colors to show automatic and manual transmission.
Load plotly package. Re-code Transmission variable (am) into “automatic” (0) and “manual” (1).
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
mtcars$am <- gsub("0", "auto", mtcars$am)
mtcars$am <- gsub("1", "manual", mtcars$am)
Plotting scatterplot of mpg vs hp with automatic transmissions in blue and manual transmissions in green.
plot_ly(mtcars, x = ~hp, y = ~mpg, type = "scatter",split = ~am)
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode